package com.sduept.nwld.dataserver.rest.fault;

import com.alibaba.fastjson.JSONArray;
import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.countanalyse.BreakerResponseTimeStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 断路器动作分析Rest服务
 * @author Ningfw
 * @date 2017-07-04
 *
 */
@RestController
@RequestMapping("/breakerAction/")
public class BreakerActionServices {

	@Autowired
	private BreakerActionCache breakerActionCache;
	@Autowired
	private SuperDAO dao;
	

	@GetMapping("/getBreakerActionByStationId/{stationId}")
	public String getBreakerActionByStationId(@PathVariable("stationId") String stationId){
		breakerActionCache.getBreakerActionByStationId(stationId);
		return null;
	}
	/**
	 * 查询全部的断路器动作时间（保护响应时间分析模块）
	 * @return
	 */

	@GetMapping("/getBreakerAction500KV")
	public String getBreakerActionAll1(){
		JSONArray jsa = new JSONArray();
		String esql = "from BreakerResponseTimeStatistics where voltageLevel like '500%'"; 
		List<BreakerResponseTimeStatistics> brts = dao.findByComplexCondition(esql, BreakerResponseTimeStatistics.class);
		for (BreakerResponseTimeStatistics brt : brts) {
			JSONArray jsArr = new JSONArray();
			jsArr.add(brt.getArea());
			jsArr.add(brt.getYear());
			jsArr.add(brt.getMonth());
			jsArr.add(brt.getAvgActTime());
			jsArr.add(brt.getMaxActTime());
			jsArr.add(brt.getVoltageLevel());
			jsa.add(jsArr);
		}
		return jsa.toString();
	}
	

	@GetMapping("/getBreakerActionByVoltage/{voltage}")
	public String getBreakerActionByVoltage(@PathVariable("voltage") String voltage){
		JSONArray jsa = new JSONArray();
		String esql = "from BreakerResponseTimeStatistics where voltageLevel = '"+voltage+"'"; 
		List<BreakerResponseTimeStatistics> brts = dao.findByComplexCondition(esql, BreakerResponseTimeStatistics.class);
		for (BreakerResponseTimeStatistics brt : brts) {
			JSONArray jsArr = new JSONArray();
			jsArr.add(brt.getArea());
			jsArr.add(brt.getYear());
			jsArr.add(brt.getMonth());
			jsArr.add(brt.getAvgActTime());
			jsArr.add(brt.getMaxActTime());
			jsArr.add(brt.getVoltageLevel());
			jsa.add(jsArr);
		}
		return jsa.toString();
	}
}
